package com.ymatou.shop.util;


import com.ymatou.shop.R;

import android.R.integer;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class DialogUtil {
	public static final int EDIT_LIVE_TITLE_FINISHED = 50;
	
	/**
	 * 5 second
	 */
	public static final int duration = 5000;
	
	public static void exitDialog(Context context){

	}
	
	/**
	 * AlertDialog 
	 * @param context
	 * @param title
	 * @param message
	 */
	public static void buildDialog(Context context, String title, String message){

	}
	
	public static void buildDialogAndFinishActivity(final Activity activity, String title, String message){

	}
	
	private static Dialog logoutDialog;
	public static void alertDialog(final Context context, String message) {
		new AlertDialog.Builder(context)
		.setMessage(message)
		.setPositiveButton(R.string.alert_dialog_ok, new OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.cancel();
			}
		})
		.show();
	}
	
	public static void alertDialog(final Context context, int resId) {
		new AlertDialog.Builder(context)
		.setMessage(resId)
		.setPositiveButton(R.string.alert_dialog_ok, new OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.cancel();
			}
		})
		.show();
	}
	
	public static void operationDialog(final Context context, OnClickListener listener, int itemsId) {
		new AlertDialog.Builder(context)
//        .setTitle(R.string.select_dialog)
//		.setAdapter(textAdapter, new OnClickListener() {
//			@Override
//			public void onClick(DialogInterface dialog, int which) {
//				// TODO Auto-generated method stub
//				
//			}
//		})
        .setItems(itemsId, listener)
        .show();
	}
	
	private static Toast toast;
	public static void toast(Context context, String text){
		toast(context, text, Toast.LENGTH_SHORT);
	}
	public static void toast(Context context, int resId){
		toast(context, resId, Toast.LENGTH_SHORT);
	}
	
	public static void toast(Context context, String text, int duration){
		toast = Toast.makeText(context, text, duration);
		toast.setGravity(Gravity.CENTER, 0, 0);
		toast.show();
	}
	public static void toast(Context context, int resId, int duration){
		toast = Toast.makeText(context, resId, duration);
		toast.setGravity(Gravity.CENTER, 0, 0);
		toast.show();
	}
	
//	public static void toastWithoutUiThread(Context context, String text){
//		Looper.prepare();
//		toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
//		toast.setGravity(Gravity.CENTER, 0, 0);
//		toast.cancel();
//		toast.show();
//	}
	
	public static void showVerticalToast(Context context, String text) {

	}
	
	public static ProgressDialog progressDialog(Context context, String text) {
		ProgressDialog progressDialog = new ProgressDialog(context);
		progressDialog.setMessage(text);
		return progressDialog;
	}
}
